package com.demo.web.model;

/**
 * @author hushengdong
 */
public class HttpResponse<T> {

    private int code;
    private boolean success;
    private String msg;
    private T data;

    public static <T> HttpResponse ok(String msg, T t) {

        HttpResponse httpResponse = new HttpResponse();
        httpResponse.setCode(200);
        httpResponse.setMsg(msg);
        httpResponse.setSuccess(true);
        httpResponse.setData(t);
        return httpResponse;
    }

    public static <T> HttpResponse ok(T t) {

        HttpResponse httpResponse = new HttpResponse();
        httpResponse.setCode(200);
        httpResponse.setMsg("请求成功");
        httpResponse.setSuccess(true);
        httpResponse.setData(t);
        return httpResponse;
    }

    public static HttpResponse fail(String msg) {

        return HttpResponse.fail(-1, msg);
    }

    public static HttpResponse fail(int code, String msg) {

        HttpResponse httpResponse = new HttpResponse();
        httpResponse.setCode(code);
        httpResponse.setMsg(msg);
        httpResponse.setSuccess(false);
        return httpResponse;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
